package com.zs.util;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * 数据连接工具类
 */
public class DBUtil {
    //连接驱动
    static String driver = "com.mysql.jdbc.Driver";
    //连接url
    static String url = "jdbc:mysql://localhost:3306/school";
    //连接用户名
    static String name = "root";
    //连接密码
    static String pwd = "root";

    /**
     * 获得数据库连接
     *
     * @return
     */
    public static Connection getConnection() {
        Connection conn = null;
        //加载驱动
        try {
            Class.forName(driver);
            //根据url，用户名，密码获得连接
            conn = DriverManager.getConnection(url, name, pwd);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return conn;

    }

}
